package trading.algo.BullToBearTask;

import java.util.Timer;
import java.util.TimerTask;

import trading.algo.TimerKillerTask;
import trading.bo.IBAccessorBO;
import trading.util.MarketTimeHelper;
import trading.util.VIXFrontMonthCheckUtil;

/**
 * Get the current price of the VIX second front month future, which we will use to determine the VIX option strike price
 * @author root
 *
 */
public class VIXSecondFrontMonthFuturePriceTask extends TimerTask {

	private IBAccessorBO ibAccessorBO;
	private MarketTimeHelper marketTimeHelper;
	
	public VIXSecondFrontMonthFuturePriceTask(IBAccessorBO ibAccessorBO, MarketTimeHelper marketTimeHelper) {
		this.ibAccessorBO = ibAccessorBO;
		this.marketTimeHelper = marketTimeHelper;
	}
	
	@Override
	public void run() {
		/**
		 * Step 1: determine VIX front month expiration
		 */
		System.out.println("Start testing VIX future front month date.");
		VIXFrontMonthCheckUtil.startTestingFrontMonthDate();
		Timer timer = new Timer();
		int taskID = 0;
		
		VIXFuturePriceTask vixFuturePriceTask = new VIXFuturePriceTask(this.ibAccessorBO, this.marketTimeHelper.getThisMonthExpiration());
        timer.schedule(vixFuturePriceTask, taskID * 1000);
        taskID += 3;
		/**
		 * Step 2: store VIX second month future price
		 */
        VIXFutureGetDataTask vixFutureGetDataTask = new VIXFutureGetDataTask(ibAccessorBO, marketTimeHelper);
        timer.schedule(vixFutureGetDataTask, taskID * 1000);
        taskID += 3;

        /**
         * Step 5: kill the timer
         */
        TimerKillerTask timerKillerTask = new TimerKillerTask(timer);
        timer.schedule(timerKillerTask, taskID * 1000);
	}

}
